import { UPDATE_STATUS, CLASSIFICATION } from '../contants';

/**
 * 书籍模型
 * @props name           书籍名称
 * @props alias          书籍别名
 * @props imgUrl         封面图片地址
 * @props author         书籍作者
 * @props des            书籍描述
 * @props classification 类别
 * @props classifyOrder  类别排序
 * @props updateStatus   更新状态
 * @props newestChapter  最新章节
 * @props totalWords     总字数
 * @props hotValue       热度值
 * @props sources        书籍爬虫来源
 */
export default function (app) {
  const { STRING, INTEGER, DATE, ENUM, ARRAY } = app.Sequelize;
  const Book = app.model.define('book', {
    name: { type: STRING(40), allowNull: false },
    aliasName: ARRAY(STRING(40)),
    imgUrl: { type: STRING, allowNull: false },
    author: { type: STRING(30), allowNull: false },
    des: STRING,
    classification: { type: ENUM, values: [Object.keys(CLASSIFICATION)] },
    classifyOrder: INTEGER,
    updateStatus: { type: ENUM, values: Object.values(UPDATE_STATUS), allowNull: false },
    newestChapter: INTEGER,
    totalWords: STRING,
    hotValue: INTEGER,
    sources: ARRAY(STRING),
    createdAt: DATE,
    updatedAt: DATE
  });

  return Book;
}
